﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Planer.Model.Validators.Base;

namespace Planer.Model.Validators
{
    public class PeriodicalActionValidator : Validator<periodical_action>
    {
        public override void Validate(periodical_action PeriodicalAction)
        {
            if (PeriodicalAction == null) throw new ArgumentNullException("PeriodicalAction", NULL_ARGUMENT_MESSAGE);

            if (PeriodicalAction.amount == 0)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Невозможно провести транзакцию с нулевой суммой");
            }

            DescriptionValidator descrValidator = new DescriptionValidator();
            descrValidator.Validate(PeriodicalAction.descr);
            if (descrValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(descrValidator.Errors);
            }

            if (PeriodicalAction.years == 0 && PeriodicalAction.months == 0 && PeriodicalAction.days == 0)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Период не может быть пустым");
            }

            YesNoValidator ynValidator = new YesNoValidator();
            ynValidator.Validate(PeriodicalAction.is_active);
            if (ynValidator.Status == OperationStatusType.ERROR)
            {
                this.status = OperationStatusType.ERROR;
                this.errors.AddRange(ynValidator.Errors);
            }
        }
    }
}
